package com.macro.mall.service.impl;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.exception.Asserts;
import com.macro.mall.mapper.CurVideoStatMapper;
import com.macro.mall.model.CurVideoStat;
import com.macro.mall.service.CurVideoStatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * CurVideoStat的服务接口的实现类
 * 
 * @author gaodx
 *
 */
@Slf4j
@Service
public class CurVideoStatServiceImpl implements CurVideoStatService {

    @Value("${log.isDebugEnabled:false}")
    private boolean isDebugEnabled;

	@Autowired
	private CurVideoStatMapper curVideoStatMapper;

	@Override
	public List<CurVideoStat> find(CurVideoStat value) {
		//TODO这里可以做通过Assist做添加查询
		List<CurVideoStat> result = curVideoStatMapper.selectCurVideoStat(null);
		if (isDebugEnabled) {
			log.debug("执行获取CurVideoStat数据集-->结果:", result);
		}
		return result;
	}
	@Override
	public CurVideoStat findOne(Long id) {
		if (id == null) {
			if (isDebugEnabled) {
				log.debug("执行通过CurVideoStat的id获得CurVideoStat对象-->失败:id不能为空");
			}
            Asserts.fail("执行通过CurVideoStat的id获得CurVideoStat对象-->失败:id不能为空");
		}
		CurVideoStat result = curVideoStatMapper.selectCurVideoStatById(id);
		if (isDebugEnabled) {
			log.debug("执行通过CurVideoStat的id获得CurVideoStat对象-->结果:", result);
		}
		return result;
	}

	@Override
	public CommonResult saveNotNull(CurVideoStat value) {
		if (value == null) {
			if (isDebugEnabled) {
				log.debug("执行将CurVideoStat中属性值不为null的数据保存到数据库-->失败:对象不能为空");
			}
                Asserts.fail("失败:对象不能为空");
		}
		int result = curVideoStatMapper.insertNotNullCurVideoStat(value);
		if (isDebugEnabled) {
			log.debug("执行将CurVideoStat中属性值不为null的数据保存到数据库-->结果:", result);
		}
            return CommonResult.success(null);
	}
	@Override
	public CommonResult updateNotNullById(CurVideoStat value) {
		if (value == null) {
			if (isDebugEnabled) {
				log.debug("执行通过CurVideoStat的id更新CurVideoStat中属性不为null的数据-->失败:对象为null");
			}
                Asserts.fail("执行通过CurVideoStat的id更新CurVideoStat中属性不为null的数据-->失败:对象为null");
		}
		int result = curVideoStatMapper.updateNotNullCurVideoStatById(value);
		if (isDebugEnabled) {
			log.debug("执行通过CurVideoStat的id更新CurVideoStat中属性不为null的数据-->结果:", result);
		}
        return CommonResult.success(null);
	}

	@Override
	public CommonResult deleteById(Long id) {
		if (id == null) {
			if (isDebugEnabled) {
				log.debug("执行通过CurVideoStat的id删除CurVideoStat-->失败:id不能为空");
			}
                Asserts.fail("执行通过CurVideoStat的id删除CurVideoStat-->失败:id不能为空");
		}
		int result = curVideoStatMapper.deleteCurVideoStatById(id);
		if (isDebugEnabled) {
			log.debug("执行通过CurVideoStat的id删除CurVideoStat-->结果:", result);
		}
        return CommonResult.success(null);
	}


}